class OverLine:
    def __init__(
        self,
        rowNum1: int,
        colNum1: int,
        cand1: int,
        rowNum2: int,
        colNum2: int,
        cand2: int,
    ):
        x1, y1, x2, y2 = over_getxy(rowNum1, colNum1, cand1, rowNum2, colNum2, cand2)
        if x1 == x2:
            self.kind: str = "y"
            self.k: float = 0.0
            self.b: float = 0.0
            self.minv: int = min(y1, y2)
            self.maxv: int = max(y1, y2)
            return
        self.kind: str = "x"
        self.k: float = round((y2 - y1) / (x2 - x1), 5)
        self.b: float = round(y1 - self.k * x1, 5)
        self.minv: int = min(x1, x2)
        self.maxv: int = max(x1, x2)

    def isOverlap(self, other: "OverLine") -> bool:
        if self.kind == "y" and other.kind == "y":
            return value_overlap(self.minv, self.maxv, other.minv, other.maxv)
        if (
            self.kind == "x"
            and other.kind == "x"
            and self.k == other.k
            and self.b == other.b
        ):
            return value_overlap(self.minv, self.maxv, other.minv, other.maxv)

        return False


def over_getxy(
    rowNum1: int, colNum1: int, cand1: int, rowNum2: int, colNum2: int, cand2: int
) -> tuple[int, int, int, int]:
    cand1 -= 1
    cand2 -= 1
    y1 = rowNum1 * 3 + cand1 // 3
    x1 = colNum1 * 3 + cand1 % 3
    y2 = rowNum2 * 3 + cand2 // 3
    x2 = colNum2 * 3 + cand2 % 3
    return x1, y1, x2, y2


def value_overlap(a0: int, a1: int, b0: int, b1: int) -> bool:
    # 规范化范围（确保起始点小于等于结束点）
    a_start, a_end = (a0, a1) if a0 <= a1 else (a1, a0)
    b_start, b_end = (b0, b1) if b0 <= b1 else (b1, b0)

    # 判断区间是否重叠的数学条件
    return (a_start < b_end) and (b_start < a_end)
